<template>
	<el-row class="content">
		<el-col :xs='24' :sm={span:6,offset:9}>
			<span class="title">欢迎登录</span>
			<el-row>
				<el-input v-model="account" placeholder="请输入账号" type="text"></el-input>
				<el-input v-model="password" type="password" placeholder="请输入密码"></el-input>
				<el-button type="primary" @click="loginin">登录</el-button>
			</el-row>
		</el-col>
	</el-row>
</template>
<script>
	export default {
		name:'Login',
		data(){
			return{
				account:'',
				password:''
			}
		},
		methods:{
			loginin(){
				let obj={
					name:this.account,
					password:this.password
				}
				let self=this;
				this.$http.post('/auth/user',obj).then( res=>{
				console.log(res.data)	
					if(res.data.success){
						sessionStorage.setItem('demo-token',res.data.token);
						this.$message({
							type:'success',
							message:'登录成功！',
							duration:1500
						})	
						self.$router.push('/todolist')
					}else{
						this.$message.error(res.data.info);
						sessionStorage.setItem('demo-token',null);
					}
				}).catch(function (error) {
   				 		console.log(error);
 				});
				
			}
		}
	}
</script>
<style scoped>
	.title{
		line-height: 30px;
	}
	.el-input{
		margin-bottom: 20px;
	}
	.el-button{
		width: 100%;
	}
</style>